<?php
if(isset($_POST['submit']))
{
    //print_r($_POST);
    
    
    
    
//THEM KHACH HANG
    $tenkhachhang   =   $_POST['tenkhachhang'];
    $gioitinh       =   $_POST['gioitinh'];
    $cmt            =   $_POST['cmt']; 
    $ngaysinh       =   $_POST['ngaysinh'];
    $sdt1           =   $_POST['sdt1'];
    $sdt2           =   $_POST['sdt2'];
    $email          =   $_POST['email'];
    
    $sql1 = mysql_query("insert into khachhang set
                                        tenkhachhang    =   '$tenkhachhang',
                                        gioitinh        =   '$gioitinh',
                                        ngaysinh        =   '$ngaysinh',
                                        sdt1            =   '$sdt1',
                                        sdt2            =   '$sdt2',
                                        email           =   '$email',
                                        cmt             =   '$cmt'
                                        ");
       
    $result1 = mysql_query($sql1);
    
    /*kiem tra xem them dc chua
    if ($result1)
    {
        print "<h2>Thêm khách ok !</h2>";
    }*/
            
            

                            

//THEM DON HANG
                        $thanhvien      =   $_POST['thanhvien']; //test                                                   
                        $donvilam       =   $_POST['donvilam'];
                        $tinhchat       =   $_POST['tinhchat'];
                        
                        //them id khach hang tu bang khach hang
                        $khachhangnew =   mysql_query("select max(khachhangid) from khachhang");
                                while ($row6 = mysql_fetch_array($khachhangnew))
                                    $khachhang = $row6[0];
                                    
                        $khuyenmai      =   $_POST['khuyenmai'];
                        $soluong        =   $_POST['soluong'];
                        $tructiepdieuphoi   =   $_POST['tructiepdieuphoi'];
                        $ngayki         =   $_POST['ngayki'];
                        $lamnhanh       =   $_POST['lamnhanh'];
                        $ngaytra        =   $_POST['ngaytra'];
                        $designer       =   $_POST['designer'];
                        
                        $mavai          =   $_POST['mavai'];
                        $kieuco         =   $_POST['kieuco'];
    if($kieuco == 1){
                    	$mauco          =   $_POST['mauco'];
                    	$mautrutren     =   $_POST['mautrutren'];
                    	$mautruduoi     =   $_POST['mautruduoi'];}
    if(isset($_POST['comu'])){
                        $comu   =   1;
                        $maumu  =   $_POST['maumu'];}
        else{           $comu   =   0;
                        $maumu  =   0;}
    if(isset($_POST['taykhacmau'])){
                        $taykhacmau   =   1;
                        $mautayao     =   $_POST['mautayao'];}
        else{           $taykhacmau   =   0;
                        $mautayao     =   0;}
    if(isset($_POST['intenrieng'])){
                        $intenrieng   =   1;}   
        else{           $intenrieng   =   0;}                                
    if(isset($_POST['co'])){
                    	$chitietthemco     =   $_POST['chitietthemco'];
                    	$mauchitietthemco  =   $_POST['mauchitietthemco'];}
        else{
                    	$chitietthemco     =   0;
                    	$mauchitietthemco  =   0;}
    if(isset($_POST['tay'])){
                    	$chitietthemtay     =   $_POST['chitietthemtay'];
                    	$mauchitietthemtay  =   $_POST['mauchitietthemtay'];}
        else{
                    	$chitietthemtay     =   0;
                    	$mauchitietthemtay  =   0;}
    if(isset($_POST['gau'])){
                    	$chitietthemgau     =   $_POST['chitietthemgau'];
                    	$mauchitietthemgau  =   $_POST['mauchitietthemgau'];}
        else{
                    	$chitietthemgau     =   0;
                    	$mauchitietthemgau  =   0;}
    
                        $chuymay        =   $_POST['chuymay'] ;
                        $chuyin         =   $_POST['chuyin'] ;
                        //$hinhtongquan       =   $_POST['hinhtongquan'];
                        //$filehinhchitiet    =   $_POST['filehinhchitiet'];
                        $sizenams       =   $_POST['sizenams'];         
                        $sizenamm       =   $_POST['sizenamm'] ;
                        $sizenaml       =   $_POST['sizenaml'] ;        
                        $sizenamxl      =   $_POST['sizenamxl'] ;
                        $sizenamxxl     =   $_POST['sizenamxxl'] ;      
                        $sizenamxxxl    =   $_POST['sizenamxxxl'] ;
                        $sizenamxxxxl   =   $_POST['sizenamxxxxl'] ;    
                        $sizenamtong    =   $_POST['sizenamtong'] ;
                        $sizenus        =   $_POST['sizenus'] ;         
                        $sizenum        =   $_POST['sizenum'] ;
                        $sizenul        =   $_POST['sizenul'] ;         
                        $sizenuxl       =   $_POST['sizenuxl'] ;
                        $sizenuxxl      =   $_POST['sizenuxxl'] ;       
                        $sizenuxxxl     =   $_POST['sizenuxxxl'] ;
                        $sizenuxxxxl    =   $_POST['sizenuxxxxl'] ;     
                        $sizenutong     =   $_POST['sizenutong'] ;
                        
                        $dongia         =   $_POST['dongia'] ;
                        $chitiettinhgia =   $_POST['chitiettinhgia']; 
                        $tongtien       =   $_POST['tongtien'] ;
                        $dattruoc       =   $_POST['dattruoc']  ;
                        $conlai       =   $_POST['conlai']  ;
      
    if ($_POST['luutam'] == 1) 
                        $tinhtrang = 0;
    else                $tinhtrang = 1;
    
    //THEM DU LIEU VAO CO SO DU LIEU
    $sql4 = "insert into donhang set thanhvien  =   '$thanhvien',
                                    tinhchat    =   '$tinhchat',
                                    donvilam    =   '$donvilam',
                                    khachhang   =   '$khachhang',
                                    tructiepdieuphoi    =   '$tructiepdieuphoi',    
                                    designer    =   '$designer',
                                    khuyenmai   =   '$khuyenmai',
                                    dongia      =   '$dongia',
                                    tongtien    =   '$tongtien',
                                    dattruoc    =   '$dattruoc',
                                    conlai      =   '$conlai',
                                    soluong     =   '$soluong',
                                    ngayki      =   '$ngayki',
                                    ngaytra     =   '$ngaytra',
                                    mavai       =   '$mavai',
                                    kieuco      =   '$kieuco',
                                    mauco       =   '$mauco',
                                    mautrutren  =   '$mautrutren',
                                    mautruduoi  =   '$mautruduoi',
                                    taykhacmau  =   '$taykhacmau',
                                    mautayao    =   '$mautayao',
                                    comu        =   '$comu',
                                    maumu       =   '$maumu',
                                    intenrieng  =   '$intenrieng',
                                    chitietthemco   =   '$chitietthemco',
                                    chitietthemtay  =   '$chitietthemtay',
                                    chitietthemgau  =   '$chitietthemgau',
                                    mauchitietthemco    =   '$mauchitietthemco',
                                    mauchitietthemtay   =   '$mauchitietthemtay',   
                                    mauchitietthemgau   =   '$mauchitietthemgau',
                                    chuymay     =   '$chuymay',
                                    chuyin      =   '$chuyin',
                                    hinhtongquan    =   '',
                                    filehinhchitiet =   '',
                                    sizenams    =   '$sizenams',
                                    sizenamm    =   '$sizenamm',    
                                    sizenaml    =   '$sizenaml',
                                    sizenamxl   =   '$sizenamxl',
                                    sizenamxxl  =   '$sizenamxxl',
                                    sizenamxxxl =   '$sizenamxxxl',
                                    sizenamxxxxl    =   '$sizenamxxxxl',
                                    sizenus     =   '$sizenus',
                                    sizenum     =   '$sizenum',
                                    sizenul     =   '$sizenul',
                                    sizenuxl    =   '$sizenuxl',
                                    sizenuxxl   =   '$sizenuxxl',
                                    sizenuxxxl  =   '$sizenuxxxl',
                                    sizenuxxxxl =   '$sizenuxxxxl',
                                    lamnhanh    =   '$lamnhanh',
                                    kenhtruyenthong =   0,
                                    luongthanhvien  =   0,
                                    tinhtrang   =   '$tinhtrang',
                                    chitiettinhgia  =   '$chitiettinhgia'   ";
        
    $result3 = mysql_query($sql4);
    /*kiem tra xem them dc chua
    if ($result3)
            print '            <h2>Gửi đơn ok !</h2>';
     */   


/*HIEN THI DON HANG DE CHECK
            $donhangnew =   mysql_query("select * from donhang where donhangid = (select max(donhangid) from donhang)");
                                while ($row7 = mysql_fetch_array($donhangnew))
                                    print_r ($row7);
*/
}
?>
